package tutorial.lite_mod.system_use.order_process;

import com.wholefarm.print.feie.Tool4FeiePrint;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import public_util.model.PublicGoodsOrderRecord;
import public_util.model.ReturnData;
import system_api_4_trade.DuzikaiSpecialApplicationFactory;
import system_api_4_trade.SpecialApplicationBefore;
import system_api_4_trade.dao.ApiPublicGoodsOrderDetailMapper;
import system_api_4_trade.dao.ApiPublicGoodsOrderRecordMapper;
import system_api_4_trade.tool_4_handle.Tool4OrderTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * 传递特殊参数, 可以演示的模板部分
 * 后面大部分的配置, 都是前端自己传过来比较稳妥
 * 每个传参对应一个相应的方法
 */
public class TemplateUtilApi {

    private static Logger logger = Logger.getLogger(TemplateUtilApi.class.getName());

    /**
     * 用户查看详情后, 数据保存,作为兴趣分析点
     * @param request
     * @param session
     * @param params2db
     * @param resultData
     * @return
     */
    public static ReturnData pre_cmd_para_copy_order_2_another(HttpServletRequest request, SqlSession session, HashMap<String, Object> params2db, ReturnData resultData)
    {
        ApiPublicGoodsOrderDetailMapper detailMapper = session.getMapper(ApiPublicGoodsOrderDetailMapper.class);
        ApiPublicGoodsOrderRecordMapper orderMapper = session.getMapper(ApiPublicGoodsOrderRecordMapper.class);
        String pre_cmd_para_copy_order_2_another = request.getParameter("pre_cmd_para_copy_order_2_another");
        if (pre_cmd_para_copy_order_2_another != null)
        {
            try
            {
                int org_id_order = Integer.valueOf(pre_cmd_para_copy_order_2_another);

                PublicGoodsOrderRecord orderRe_org = orderMapper.findOnePublicGoodsOrderRecord(Integer.valueOf(org_id_order));
                if (orderRe_org == null)
                {
                    resultData.setMsg("源订单为空");
                    resultData.setMsg_en("source order is empty");
                    return resultData;
                }
                PublicGoodsOrderRecord new_record = Tool4OrderTemplate.copy_order(session, orderRe_org, orderMapper, detailMapper, resultData, null);
                if (new_record == null)
                {
                    resultData.setMsg("copy失败");
                    resultData.setMsg_en("dest order is failed");
                    return resultData;
                }
                HashMap<String, Object> returnData = resultData.getReturnData();
                returnData.put("unfinish_order_4_copy_from_another", new_record);//copy别人的订单
            }catch (Exception e)
            {
                ReturnData returnData = new ReturnData();
                returnData.setMsg("订单ID不对");
            }
        }


        return null;
    }

}

//前后端插入msg日志信息过来, 并方便及时清理
